package com.qulai.web.controller.amazon_us;

import com.qulai.amazon_us.domain.amazon_us.AmazonUsContent;
import com.qulai.amazon_us.service.amazon_us.IAmazonUsContentService;
import com.qulai.common.annotation.Log;
import com.qulai.common.core.controller.BaseController;
import com.qulai.common.core.domain.AjaxResult;
import com.qulai.common.core.page.TableDataInfo;
import com.qulai.common.enums.BusinessType;
import com.qulai.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品文案Controller
 *
 * @author hunan
 * @date 2025-01-30
 */
@RestController
@RequestMapping("/amazon_us/content")
public class AmazonUsContentController extends BaseController {
    @Autowired
    private IAmazonUsContentService amazonUsContentService;

    /**
     * 查询商品文案列表
     */
    @PreAuthorize("@ss.hasPermi('amazon_us:content:list')")
    @GetMapping("/list")
    public TableDataInfo list(AmazonUsContent amazonUsContent) {
        startPage();
        List<AmazonUsContent> list = amazonUsContentService.selectAmazonUsContentList(amazonUsContent);
        return getDataTable(list);
    }

    /**
     * 导出商品文案列表
     */
    @PreAuthorize("@ss.hasPermi('amazon_us:content:export')")
    @Log(title = "商品文案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AmazonUsContent amazonUsContent) {
        List<AmazonUsContent> list = amazonUsContentService.selectAmazonUsContentList(amazonUsContent);
        ExcelUtil<AmazonUsContent> util = new ExcelUtil<AmazonUsContent>(AmazonUsContent.class);
        util.exportExcel(response, list, "商品文案数据");
    }

    /**
     * 获取商品文案详细信息
     */
    @PreAuthorize("@ss.hasPermi('amazon_us:content:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(amazonUsContentService.selectAmazonUsContentById(id));
    }

    /**
     * 新增商品文案
     */
    @PreAuthorize("@ss.hasPermi('amazon_us:content:add')")
    @Log(title = "商品文案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AmazonUsContent amazonUsContent) {
        amazonUsContent.setUpdateBy(getUsername());
        return toAjax(amazonUsContentService.insertAmazonUsContent(amazonUsContent));
    }

    /**
     * 修改商品文案
     */
    @PreAuthorize("@ss.hasPermi('amazon_us:content:edit')")
    @Log(title = "商品文案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AmazonUsContent amazonUsContent) {
        amazonUsContent.setUpdateBy(getUsername());
        return toAjax(amazonUsContentService.updateAmazonUsContent(amazonUsContent));
    }

    /**
     * 删除商品文案
     */
    @PreAuthorize("@ss.hasPermi('amazon_us:content:remove')")
    @Log(title = "商品文案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(amazonUsContentService.deleteAmazonUsContentByIds(ids));
    }
}
